package cn.zmit.kuxi.holder;

import com.xdroid.common.utils.PreferenceHelper;
import com.xdroid.functions.holder.ViewHolderBase;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import cn.zmit.kuxi.R;
import cn.zmit.kuxi.activity.HisCenterActivity;
import cn.zmit.kuxi.contants.SPConstants;
import cn.zmit.kuxi.contants.Url;
import cn.zmit.kuxi.entity.JoinUserEntity;
import cn.zmit.kuxi.image.ImageDisplayer;

/** * @author chenxu @parameter * @return */
public class JoinUserHolder extends ViewHolderBase<JoinUserEntity> {
	private ImageView userPic;
	private TextView name, phone, joinNum, lastTime;
	private Context context;
	private LinearLayout llRoot;

	@SuppressLint("InflateParams")
	@Override
	public View createView(LayoutInflater layoutInflater) {
		context = layoutInflater.getContext();
		View view = layoutInflater.inflate(R.layout.item_join_user, null);
		userPic = (ImageView) view.findViewById(R.id.imag_userPic);
		name = (TextView) view.findViewById(R.id.tv_joinUserName);
		phone = (TextView) view.findViewById(R.id.tv_joinUserPhone);
		joinNum = (TextView) view.findViewById(R.id.tv__joinNum);
		lastTime = (TextView) view.findViewById(R.id.tv_last_joinTime);
		llRoot = (LinearLayout) view.findViewById(R.id.ll_root);
		return view;
	}

	@Override
	public void showData(int position, final JoinUserEntity itemData) {
		if (itemData.getUrl() != null && itemData.getUrl().length() > 0) {
			ImageDisplayer.getInstance().dispalyImageWithRadius(
					Url.IMAGR_ROOT + itemData.getUrl(), userPic, 0);
		} else {
			userPic.setImageResource(R.drawable.user_pic_def);
		}
		name.setText("昵称:" + itemData.getName() + "   " + "("
				+ itemData.getIP() + ")");
		if (itemData.getPhone() != null && itemData.getPhone().length() == 11) {
			phone.setText("参与用户:" + itemData.getPhone());
		}

		joinNum.setText("参与次数:" + itemData.getJoinNum());
		lastTime.setText("参与时间:" + itemData.getLastTime());
		llRoot.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				final Boolean has_login = PreferenceHelper.readBoolean(context,
						SPConstants.SHARED_PREFERENCE_NAME,
						SPConstants.HAS_LOGGED, false);
				if (has_login) {
					Intent intent = new Intent();
					Bundle bundle = new Bundle();
					bundle.putString("win_id", itemData.getUser_id());
					intent.putExtras(bundle);
					intent.setClass(context, HisCenterActivity.class);
					context.startActivity(intent);
				} else {
					Toast.makeText(context, "登陆后可查看!", 0).show();
				}
			}
		});
	}

}
